<?php
// +----------------------------------------------------------------------
// | 青航系统 [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2023-永久 https://www.feifeiyu.club/ All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 青航-不吃芒果 <1716892803@qq.com>
// +----------------------------------------------------------------------
namespace app\admin\model;
use think\Model;

class Article extends Model{
    
    // 移动分类
    public static function content_remove($id,$catid) {
        $r = D('article')->where('id',$id)->update(['catid'=>$catid]);
        return $r;
    }
     
     
    // 复制内容 
    public static function content_copy($id,$catid) {
        $res = D('article')->where('id',$id)->find();
    	$res['id'] = '';
    	$res['catid'] = $catid;
		$res['is_push'] = 0;
    	$res['updatetime'] = time();
        // 	直接插入数据
    	D('article')->insert($res);
        // 	返回ID的主键值
    	$contentId =  D('article')->getLastInsID();
    	$r = D('article')->where('id', $contentId)->update(['url'=>'/'.'show'.'/'.$contentId.'.html']);
        return $r;
    }
    
    
    
    
    // 添加数据
    public static function content_add($data, $isimport = 0,$number = 0) {
        $data['issystem']  = $isimport ? 0 : 1;
    	$data['inputtime'] = strtotime($data['inputtime']);
    	$data['updatetime'] = time();
    	$data['description'] = empty($data['description']) ? str_cut(strip_tags($data['content']),250) : $data['description'];
    	$data['userid'] = Session('adminid');
    	$data['status'] = isset($data['status']) ? intval($data['status']) : 1;
    	$data['url'] = '';
    	$data['flag'] = '';
    	$data['up'] = $number;
    	$data['down'] = $number;
    	$data['is_push'] = $number;
    	// 	直接插入数据
    	D('article')->strict(false)->insert($data,true);
    	// 	返回ID的主键值
    	$contentId = D('article')->getLastInsID();
    	//修改表的url
    	$r = D('article')->where('id',$contentId)->update(['url'=>'/'.'show'.'/'.$contentId.'.html']);
    	return $r;
    }
		
	
	// 编辑数据
    public static function content_edit($data) {
        $data['inputtime'] = strtotime($data['inputtime']);
    	$data['updatetime'] = time();
        $r = D('article')->strict(false)->where('id', $data['id'])->update($data,true);
        return $r;
    }
	
    
}